package com.antaohua.platfrom.framework.base.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.antaohua.platfrom.framework.base.utils.Condition;
import com.antaohua.platfrom.framework.base.utils.PageUtil;
import com.antaohua.platfrom.framework.base.interfase.BaseDao;
import com.antaohua.platfrom.framework.base.interfase.BaseService;
import com.antaohua.platfrom.framework.base.model.UUIDIdentityModel;
import com.antaohua.platfrom.framework.container.ThreeColumn;
import com.antaohua.platfrom.framework.container.ThreeEntry;


public abstract class BaseServiceImpl<E extends UUIDIdentityModel> implements BaseService<E>{

	@Autowired
	protected BaseDao<E> dao;


	
	@Transactional(readOnly=false)
	public E save(E entity) {
		return dao.save(entity);
	}
	
	@Transactional(readOnly=false)
	public List<E> save(List<E> entitys) {
		return dao.save(entitys);
		
	}
	
	@Transactional(readOnly=false)
	public E update(E entity) {
		return dao.update(entity);
	}
	
	@Transactional(readOnly=false)
	public int updateById(String updateProperty,Object updateData,String id) {
		return dao.updateById(updateProperty, updateData, id);
	}
	
	@Transactional(readOnly=false)
	public int updateByProperty(String updateProperty,Object updateData,String whereProperty,Object whereData) {
		return dao.updateByProperty(updateProperty, updateData, whereProperty, whereData);
	}
	
	@Transactional(readOnly=false)
	public int updateByPropertys(Map<String, Object> updateData,ThreeColumn<String, Condition, Object> wherePropertys) {
		return dao.updateByPropertys(updateData, wherePropertys);
	}
	
	@Transactional(readOnly=false)
	public void delete(E entity) {
		dao.delete(entity);
	}
	
	@Transactional(readOnly=false)
	public int deleteById(String id) {
		return dao.deleteById(id);
	}
	
	@Transactional(readOnly=false)
	public int deleteByIds(String[] ids) {
		return dao.deleteByIds(ids);
	}
	
	@Transactional(readOnly=false)
	public int deleteByProperty(String whereProperty,Object whereData) {
		return dao.deleteByProperty(whereProperty, whereData);
	}
	
	@Transactional(readOnly=false)
	public int deleteByPropertys(ThreeColumn<String, Condition, Object> wherePropertys) {
		return dao.deleteByPropertys(wherePropertys);
	}
	
	@Transactional(readOnly=true)
	public E findById(String id) {
		return dao.findById(id);
	}
	
	@Transactional(readOnly=true)
	public List<E> findByIds(String [] ids){
		return dao.findByIds(ids);
	}
	
	@Transactional(readOnly=true)
	public List<E> findByIds(List<String> ids){
		return dao.findByIds(ids);
	}
	
	@Transactional(readOnly=true)
	public List<E> findAll(){
		return dao.findAll();
	}
	
	@Transactional(readOnly=true)
	public List<E> findAllOrder(String orderProperty , Boolean asc){
		return dao.findAllOrder(orderProperty, asc);
	}
	
	@Transactional(readOnly=true)
	public PageUtil<E> findAllFotPage(PageUtil<E> page){
		return dao.findAllFotPage(page);
	}
	
	@Transactional(readOnly=true)
	public PageUtil<E> findAllPageOrder(PageUtil<E> page,String orderProperty , Boolean asc){
		return dao.findAllPageOrder(page, orderProperty, asc);
	}
	
	@Transactional(readOnly=true)
	public List<E> findByProperty(String whereProperty,Object whereData){
		return dao.findByProperty(whereProperty,whereData);
	}
	
	@Transactional(readOnly=true)
	public List<E> findByProperty(ThreeEntry<String, Condition, Object> whereProperty){
		return dao.findByProperty(whereProperty);
	}
	
	@Transactional(readOnly=true)
	public List<E> findByPropertys(Map<String, Object> whereProperty){
		return dao.findByPropertys(whereProperty);
	}
	
	@Transactional(readOnly=true)
	public List<E> findByPropertys(ThreeColumn<String, Condition, Object> wherePropertys){
		return dao.findByPropertys(wherePropertys);
	}
	
	@Transactional(readOnly=true)
	public List<E> findByPropertyOrder(String whereProperty,Object whereData,String orderProperty , Boolean asc){
		return dao.findByPropertyOrder(whereProperty, whereData, orderProperty, asc);
	}
	
	@Transactional(readOnly=true)
	public List<E> findByPropertysOrder(ThreeColumn<String, Condition, Object> wherePropertys,Map<String, Boolean> orders){
		return dao.findByPropertysOrder(wherePropertys, orders);
	}
	
	@Transactional(readOnly=true)
	public PageUtil<E> findPageByPropertyOrder(PageUtil<E> page,String whereProperty,Object whereData,String orderProperty , Boolean asc){
		return dao.findPageByPropertyOrder(page, whereProperty, whereData,orderProperty, asc);
	}
	
	@Transactional(readOnly=true)
	public PageUtil<E> findPageByPropertyOrder(PageUtil<E> page,ThreeEntry<String, Condition, Object> whereProperty,String orderProperty , Boolean asc){
		return dao.findPageByPropertyOrder(page,whereProperty,orderProperty ,asc);
	}
	
	@Transactional(readOnly=true)
	public PageUtil<E> findPageByPropertysOrder(PageUtil<E> page,ThreeColumn<String, Condition, Object> wherePropertys,String orderProperty , Boolean asc){
		return dao.findPageByPropertysOrder(page, wherePropertys, orderProperty,asc);
	}
	
	@Transactional(readOnly=true)
	public PageUtil<E> findPageByPropertysOrder(PageUtil<E> page,ThreeColumn<String, Condition, Object> wherePropertys,Map<String, Boolean> orders){
		return dao.findPageByPropertysOrder(page, wherePropertys, orders);
	}
	
	@Transactional(readOnly=true)
	public Long countByPropertys(ThreeColumn<String, Condition, Object> wherePropertys){
		return dao.countByPropertys(wherePropertys);
	}
	
	@Transactional(readOnly=true)
	public Long countByProperty(ThreeEntry<String, Condition, Object> whereProperty){
		return dao.countByProperty(whereProperty);
	}
	
	@Transactional(readOnly=true)
	public Long countByProperty(String whereProperty,Object whereData){
		return dao.countByProperty(whereProperty, whereData);
	}
	
	@Transactional(readOnly=true)
	public Long count(){
		return dao.count();
	}

}
